<template>
  <div style="line-height: 0;">
    <div style="margin-top: 15px; margin-bottom: 15px; line-height: 0; text-align: left;">
      <div style="margin-top: 15px; margin-bottom: 15px; line-height: 0; text-align: left;">
        <el-row>
          <label style="margin-left: 10px;">商家名称：</label>
          <el-input style="width: 200px;" prefix-icon="el-icon-search" v-model="params.username" placeholder="请输入商家名称"></el-input>
          &nbsp;&nbsp;&nbsp;
          <label>树苗名称：</label>
          <el-input style="width: 200px;" prefix-icon="el-icon-search" v-model="params.treename" placeholder="请输入树苗名称"></el-input>
          &nbsp;&nbsp;&nbsp;
          <el-button type="warning" round style="margin-left: 10px;" @click="findOtherTree">查询</el-button>
          &nbsp;&nbsp;&nbsp;
          <el-button type="warning" round style="margin-left: 10px;" @click="reset">重置</el-button>
        </el-row>
      </div>
      <div>
        <el-table
            :data="tableData"
            border
            style="width: 100%">
          <el-table-column prop="tree_id" v-if="false"></el-table-column>
          <el-table-column prop="treename" label="树苗名称" width="180"></el-table-column>
          <el-table-column prop="username" label="商家名称" width="180"></el-table-column>
          <el-table-column prop="treetime" label="树苗年份" width="180"></el-table-column>
          <el-table-column prop="treeprice" label="树苗价格" width="180"></el-table-column>
          <el-table-column prop="treetypename" label="树苗种类" width="180"></el-table-column>
          <el-table-column prop="sellnum" label="在售数量"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="primary" @click="detail(scope.row)">查看详情</el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

    <div class="block" style="text-align: center;">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="params.pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="params.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
    <!--编辑-->
    <div >
      <el-dialog title="树苗信息" :visible.sync="dialogFormVisible" >
        <el-form :model="form" style="text-align: center;">
          <el-form-item label="树苗名称" :label-width="formLabelWidth" disabled>
            <el-input v-model="form.treename" autocomplete="off" style="width: 80%;"></el-input>
          </el-form-item>
          <el-form-item label="树苗年份" :label-width="formLabelWidth">
            <el-input v-model="form.treetime" autocomplete="off" style="width: 80%;"></el-input>
          </el-form-item>
          <el-form-item label="树苗价格" :label-width="formLabelWidth">
            <el-input v-model="form.treeprice" autocomplete="off" style="width: 80%;"></el-input>
          </el-form-item>
          <el-form-item label="树苗种类" :label-width="formLabelWidth">
            <el-select v-model="form.treetypename" style="width: 80%;">
              <el-option label="常绿乔木类" value="常绿乔木类"></el-option>
              <el-option label="常绿灌木类" value="常绿灌木类"></el-option>
              <el-option label="落叶乔木类" value="落叶乔木类"></el-option>
              <el-option label="落叶灌木类" value="落叶灌木类"></el-option>
              <el-option label="果树苗木类" value="果树苗木类"></el-option>
              <el-option label="绿化苗木类" value="绿化苗木类"></el-option>
              <el-option label="盆景绿植类" value="盆景绿植类"></el-option>
              <el-option label="彩叶苗木类" value="彩叶苗木类"></el-option>
              <el-option label="其他苗木类" value="其他苗木类"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer" >
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="submit">确 定</el-button>
        </div>
      </el-dialog>
    </div>


  </div>

</template>
<script>
import request from "@/utils/request";
export default {
  data() {
    return {
      params: {
        username:'',
        treename: '',
        pageNum: 1,
        pageSize: 10
      },
      tableData: [],
      total: 0,
      formLabelWidth: '190px',
      dialogFormVisible: false,
      form : {},
      user:JSON.parse(sessionStorage.getItem("user"))
    }
  },
  //在页面加载的时候，做一些事情
  created() {
    this.findOtherTree();
  },
  //定义一些页面上触发事件调用的方法
  methods:{
    handleSizeChange(pageSize){
      this.params.pageSize = pageSize;
      this.findOtherTree();
    },
    handleCurrentChange(pageNum){
      this.params.pageNum = pageNum;
      this.findOtherTree();
    },
    findOtherTree() {
      request.post("/tree/findothertree/"+ this.user.userId,this.params).then(res => {
        if (res.code === '0'){
          this.tableData = res.data.list;
          this.total = res.data.total;
        } else{
          this.$message({
            message: res.msg,
            type: 'error'
          })
        }
      })
    },
    detail(obj){
      let url = '/businessdetailview?treeId=' + obj.treeId;
      location.href = url;
    },
    reset(){
      this.params = {
        pageNum: 1,
        pageSize: 5,
        treename: '',
      }
      this.findOtherTree();
    },
    submit(){
      request.post("/tree/treeedit",this.form).then(res => {
        if(res.code === '0'){
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          location.reload();
        }
        else{
          this.$message({
            message: res.msg,
            type: 'error'
          })
        }
      })
      this.dialogFormVisible = false;
      this.findOtherTree();
    }
  }
}
</script>